package com.jie.jie.xiaohua.model;

import com.google.gson.Gson;
import com.jie.jie.xiaohua.app.XiaohuaRetrofitManager;
import com.jie.jie.xiaohua.app.XiaohuaServier;
import com.jie.jie.xiaohua.contract.XiaohuaContract;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by jie on 2017/1/24.
 */

public class XiaohuaModel implements XiaohuaContract.Model{

    private final static String KEY = "fa9a1c350bd69b141818713bd781e65d";

    public  Observable<XiaohuaBean> getXiaohua(String sort, String time, int page, int pagesize) {
        return XiaohuaRetrofitManager.getInstance()
                .createService(XiaohuaServier.class)
                .getXiaohua(KEY, sort, page, pagesize, time)
                .map(new Func1<String, XiaohuaBean>() {
                    @Override
                    public XiaohuaBean call(String s) {
//                        LogUtils.loge(s);
                        return new Gson().fromJson(s, XiaohuaBean.class);
                    }
                })
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread());

    }
}
